package com.zg.exception;

import lombok.Data;

@Data
public class Result<T> {

    private int code;
    private String message;
    private T data;
    private long timestamp;


    public Result(){
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> Result<T> success(){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnums.RC100.getCode());
        result.setMessage(ResultCodeEnums.RC100.getMessage());
        return result;
    }

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCodeEnums.RC100.getCode());
        result.setMessage(ResultCodeEnums.RC100.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(int code,String message){
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> fail(ResultCodeEnums resultCodeEnums){
        Result<T> result = new Result<>();
        result.setCode(resultCodeEnums.getCode());
        result.setMessage(resultCodeEnums.getMessage());
        return result;
    }
}
